package com.wxx.message;

import com.wxx.bean.DiskInfoBean;
import com.wxx.bean.MemoryInfoBean;
import com.wxx.bean.ProBean;
import com.wxx.utils.IPUtil;
import com.wxx.utils.OshiUtils;

import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author: wxx
 * @date: 2024-08-16 16:49
 * @description todo 描述信息
 */
public abstract class MessageSenderAbs implements IMessageSender {

    static SimpleDateFormat instance = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private ProBean proBean;

    @Override
    public void init(ProBean proBean) {
        this.proBean = proBean;
    }

    @Override
    public String getMsg() {
        StringBuilder content = null;
        try {
            String hostName = InetAddress.getLocalHost().getHostName();
            content = new StringBuilder();
            //ip信息
            List<String> ipList = IPUtil.getIpList();
            //内存
            MemoryInfoBean memoryInfo = OshiUtils.getMemoryInfo();
            //硬盘
            List<DiskInfoBean> diskInfo = OshiUtils.getDiskInfo();
            //cpu温度
            double cpuTemperature = OshiUtils.getCpuTemperature();
            content.append(proBean.getHostName() + "-" + hostName + " " + instance.format(System.currentTimeMillis()) + "\n");
            content.append("ip信息:" + ipList.toString() + "\n");
            content.append("内存信息:" + memoryInfo + "\n");
            content.append("硬盘信息:" + diskInfo + "\n");
            content.append("cpu温度:" + cpuTemperature);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return content.toString();
    }

    @Override
    public abstract boolean sendMessage(String content);
}
